GameAPI
GameAPI is a lightweight and easy to use library that you can use to - you guessed it - make games. The library uses a system of automatically drawn and bounded actors and it does most of the work that you would have to normally do yourself. Because of the graphical limitations of CraftOS, the interface is in an ascii-type style, a text character representing each actor. The script may be obtained at http://pastebin.com/5WX5GjAM. To use the library download the script, name it 'gameapi' and place it in the directory: .minecraft/mods/ComputerCraft/lua/rom/programs At the top of your game script type the line shell.run('gameapi'). Function Reference actor:new(x, y, charbounded) returns a new actor at the x and y positions on the terminal bounded is a boolean which will determine whether or not your actor's movement is limited to the console window, true by default. actor.x the actor's x position actor.y the actor's y position actor.char the character representing the actor on screen actor.bounded whether or not the actor can go outside the screen actor:setPos(x,y) sets the actor's position **this method and other positioning methods must be used in order for the actor's position to be updated onscreen actor:addPos(x,y) adds to the actor's position actor:setX(n) sets the actor's x position to n actor:setY(n) sets the actor's y position to n actor:addX(n) adds n to the actor's x position actor:addY(n) adds n to the actor's y position actor:setChar(char) change the actor's character to char game.key(k) user defined, triggered when a key is pressed game.update() user defined, triggered when a new frame is drawn game.start() required for the game to start, obviously **any code after this function will not be ran until the game has stopped game.stop() quit the program Example Program - Simple Player Movement Below is an example program that shows how you would go about moving your character. shell.run('gameapi') player = actor:new(1,10,'O') --basic player movement function game.key(k) if k 203 then --left player:addX(-1) player:setChar('<') elseif k 205 then --right player:addX(1) player:setChar('>') elseif k 200 then --up player:addY(-1) player:setChar('^') elseif k 208 then --down player:addY(1) player:setChar('v') end end game.start() --NEEDED Explanation --basic player movement function game.key(k) --setting variable for k if k 203 then --left --saying if the key you press is 203 then player:addX(-1) --moving your guy left 1 player:setChar('<')--and changing him to the < elseif k 205 then --right player:addX(1)--moving right player:setChar('>') elseif k 200 then --up player:addY(-1)--going up player:setChar('^') elseif k 208 then --down player:addY(1)--and VVVVV player:setChar('v') end end The first line runs the api which gives the game access to it's scripts. The next line creates the player object at the specified X and Y position with the character representing it, O. Under 'game.key' k is the numeric code for which key the player has pressed. The script checks for different values of 'k' and moves the player in the direction corresponding to the key pressed. The last line has to be the most important thing you need to use this api. Credits This API was created by Kingdaro, please do not claim as your own once used. C: Category:Libraries Category:User Content Category:API